**********************************************************************
*Master analysis file 
*Run on Elevance server
**********************************************************************
global code  "<folder with code>"
global sdb   "<folder with Elevance data>"
global aha   "<folder with AHA data>"
global hcris "<folder with HCRIS data>"
global op    "<folder with output>"
global reg   "<folder with regression files>"
cd "$code"

set more off
set matsize 2000
set emptycells drop
set scheme s2color8	
graph set window fontface "Times New Roman"
pause on 
			
**********************************************************************
	*I. PREPARE REGRESSION INPUTS
	*Data prep: This file assumes the construction of episode files from Elevance, 
	*which include spending summary and readmission variables. These have been 
	*merged to American Hospital Association (AHA) IDs and mergers and saved at 
	*the episode and hospital-year levels. These processing steps are described 
	*in Appendix A1-A4. 
	*The code below constructs the inputs files to all regressions, Tables, and 
	*Figures using Elevance data.
	
	*0. Process public data files 
	do "create_hcris_vars.do"
	
	*1. Create regression files 
	forval i = 1/2 {
	global option `i' 
	do "create_regdata_FULL.do"
	}
	
	*2. Match treated to control hospitals 
	forval i = 1/4 {
	global option `i' 
	do "match.do"
	}
	forval i = 1/2 {
	global option `i' 
	do "create_regdata_FULL.do"
	}
		
	*3. Identify & summarize deals 
	*Table 2
	*Figure 2(a)
	do "create_deals.do"
	forval i = 1/2 {
	global option `i' 
	do "create_regdata_FULL.do"
	}
	
	*4. Create cardiac regression file
	forval i = 1/2 {
	global option `i' 
	do "create_regdata_QUALITY.do"
	}
	
**********************************************************************
	*II. ANALYSIS 
	*The below files construct the Tables and Figures that use Elevance data.
	*1. Maps & motivation figures
	*Figures 1, 2(b), A1(b), A2
	do "analysis_aha.do"
	
	*2. Main regressions
	*Tables 3, 5, 6, A4, A6, A8, A9
	*Figure 2(a), 3, 5, A4, A5, A6
	forval i = 1/2 {
	global option `i' 
	do "analysis_FULL.do"
	}
	
	*3. Robustness, heterogeneity, & standardized differences
	*Tables 3, 4, 7, A2, A3, A5, A6, A7, A10
	*Figure A3(a) 
	forval i = 3/4 {
	global option `i' 
	do "analysis_FULL.do"
	}
	
	*4. Test IS vs SS coeffs 
	*Figure 4 
	forval i = 5/6 {
	global option `i' 
	do "analysis_FULL.do"
	}
	
	*5. Summary stats 
	*Tables 1, A1
	global option 7 
	do "analysis_FULL.do"
	
	*6. Quality regressions
	*Tables 6, 7, A3, A7, A9, A10
	*Figure 7, A5(a), A7
	forval i = 1/2 {
	global option `i' 
	do "analysis_QUALITY.do"
	}
		
	*7. Extensive margin regressions
	*Tables 5, A8
	*Figure A3(b)
	global analysis = 1 
	forval i = 1/2 {
	global option `i' 
	do "extensive.do"
	}
	
	*8. Scatterplots
	*Figures 6, A3(c,d), A5(c)
	do "create_scatterdata.do"
	do "analysis_scatterdata.do"